//
//  MSSeeAttendanceStatisticsController.m
//  觅尚
//
//  Created by No.8 on 2019/4/10.
//  Copyright © 2019 No.8. All rights reserved.
//

#import "MSSeeAttendanceStatisticsController.h"
#import "MSSeeStatisticsCell.h"
#import "MSScreenButton.h"
#import "MSAttendanceScreenController.h"
#import "MSSetRoomManagementController.h"
#import "MSScreenSexButton.h"
#import <BRPickerView.h>
#import "BRTextField.h"
#import "NSDate+BRAdd.h"
#import "MSPrensetView.h"
#import "HMDatePickView.h"
#import "HQPickerView.h"
#import "GFAddressPicker.h"
#import "MSCompanyController.h"
#import "FYLCityPickView.h"
#import "MSAttendanceListModel.h"
#import "zySheetPickerView.h"
#import "MSShowPersonController.h"
#define pageSize 20

// 注意const的位置
static NSString *const cellId = @"cellId";
static NSString *const headerId = @"headerId";
static NSString *const footerId = @"footerId";

@interface MSSeeAttendanceStatisticsController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout,HQPickerViewDelegate>
{
    CustomNavigationBar *naviagtionBar;
    BOOL _isGrid;
    BOOL _isRemove;
    NSInteger page;
    NSInteger count;
}
/** tableview */
@property (strong,nonatomic)UICollectionView * CollectionView;

/** 头部视图 */
@property(strong,nonatomic)UIView *CollectionHeaderView;

/** 数组*/
@property(nonatomic,strong)NSMutableArray *attendanceListArray;


/** 遮盖层*/
@property(nonatomic,strong)UIView *backView;


/** 弹出View*/
@property(nonatomic,strong)UIView *showView;


/** <#name#>*/
@property(nonatomic,strong)MSScreenButton *screenButton;


/** 选择按钮*/
@property(nonatomic,strong)UIButton *selectedButton;

/** 性别选择*/
@property(nonatomic,strong)UIButton *SexSelectedButton;

@property (nonatomic, strong) GFAddressPicker *pickerView;
/** 表头*/
@property(nonatomic,strong)MSPrensetView *PrensetView;

@property (nonatomic, strong) UITableView *tableView;


/** 城市*/
@property(nonatomic,strong)UIButton *NativeButton;

/** <#name#>*/
@property(nonatomic,strong)UIButton *nationalityButton;

/** <#name#>*/
@property(nonatomic,strong)UITextField *ageTextField;

/** <#name#>*/
@property(nonatomic,strong)UITextField *twoageTextField;

/** <#name#>*/
@property(nonatomic,strong)UITextField *heightTextField;

/** <#name#>*/
@property(nonatomic,strong)UITextField *twoheightTextField;


@end

@implementation MSSeeAttendanceStatisticsController

- (int)navBarBottom {
    if ([WRNavigationBar isIphoneX]) {
        return 88;
    } else {
        return 64;
    }
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:YES];
    self.navigationController.navigationBar.hidden = YES;
    self.attendanceListArray = [NSMutableArray new];
    Prepare *header = [Prepare headerWithRefreshingTarget:self refreshingAction:@selector(MJChiBaoZiHeaderRefresh)];
    // 隐藏时间
    header.lastUpdatedTimeLabel.hidden = YES;
    header.stateLabel.hidden = YES;
    // 马上进入刷新状态
    self.CollectionView.mj_header = header;
    [self.CollectionView.mj_header beginRefreshing];
}
- (void)MJChiBaoZiHeaderRefresh{
    page = 1;
    [self ReloadData];
}
- (void)MJChiBaoZiFootderRefresh{
    if (count / pageSize < page) {
        [MBManager showBriefAlert:@"没有更多数据了"];
    }else{
        page++;
    }
    [self FootderRefreshReloadData];

}
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:YES];
    self.navigationController.navigationBar.hidden = YES;
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    _isGrid = YES;
    _isRemove = NO;
    [self CreateNavigationBar];
    
    
    [self CreatCollectionView];
    
    [self CreatCollectionHeaderView];
    
    
    PrepareFooter *footder = [PrepareFooter footerWithRefreshingTarget:self refreshingAction:@selector(MJChiBaoZiFootderRefresh)];
    // 马上进入刷新状态
    self.tableView.mj_footer = footder;
}
- (void)ReloadData{
    [MBManager showLoading];
    [self.attendanceListArray removeAllObjects];
    //年龄小
    
    NSMutableDictionary * params = [NSMutableDictionary dictionary];
    
    if (self.ageTextField.text.length == 0) {
        
        params[@"minAge"] = @0;
    }else{
        params[@"minAge"] = self.ageTextField.text;
    }
    
    //年龄大
    if (self.ageTextField.text.length == 0) {
        params[@"maxAge"] = @0;
    }else{
        params[@"maxAge"] = self.ageTextField.text;
    }
    
    //身高小
    if (self.heightTextField.text.length == 0) {
        params[@"minHeight"] = @0;
    }else{
        params[@"minHeight"] = self.heightTextField.text;
    }
    
    //身高大
    if (self.twoheightTextField.text.length == 0) {
        params[@"maxHeight"] = @0;
    }else{
        params[@"maxHeight"] = self.twoheightTextField.text;
    }
    
    //性别
    if (self.SexSelectedButton.tag == 100) {
        params[@"sex"] = @1;
    }else if (self.SexSelectedButton.tag == 101) {
       params[@"sex"] = @0;
    }else{
        params[@"sex"] = @3;
    }
    
    
    //特长
    if (self.selectedButton.tag == 10) {
        params[@"speciality"] = @1;
    }else if (self.SexSelectedButton.tag == 11) {
        params[@"speciality"] = @2;
    }else if (self.SexSelectedButton.tag == 12) {
        params[@"speciality"] = @3;
    }else if (self.SexSelectedButton.tag == 13) {
        params[@"speciality"] = @4;
    }else{
        params[@"speciality"] = @0;
    }
    
    params[@"busId"] = [WYCAccountTool unarchivebelongBusid];
    if (self.nationalityButton.titleLabel.text == nil || self.nationalityButton.titleLabel.text == NULL || [self.nationalityButton.titleLabel.text isKindOfClass:[NSNull class]] || [[self.nationalityButton.titleLabel.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] == 0) {
        params[@"province"] = @"";
    }else if([self.nationalityButton.titleLabel.text isEqualToString:@"请选择"]){
        params[@"province"] = @"";
    }else{
        params[@"province"] = [NSString stringWithFormat:@"%@",self.nationalityButton.titleLabel.text];
    }
    
     if (self.NativeButton.titleLabel.text == nil || self.NativeButton.titleLabel.text == NULL || [self.NativeButton.titleLabel.text isKindOfClass:[NSNull class]] || [[self.NativeButton.titleLabel.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] == 0) {
        params[@"country"] = @"";
     }else if([self.NativeButton.titleLabel.text isEqualToString:@"请选择"]){
         params[@"province"] = @"";
     }else{
        params[@"country"] = [NSString stringWithFormat:@"%@",self.NativeButton.titleLabel.text];
    }
    params[@"page"] = @(page);
    params[@"pageSize"] = @(pageSize);
    WYCLog(@"--------%@",params);
//    WYCLog(@"--------%@",self.nationalityButton.titleLabel.text);
    [HTTPRequest POST:MSattendancePersonnel params:params succeed:^(id responseObject) {
        WYCLog(@"--------%@",responseObject);
        if (CodeStr) {
            count = [responseObject[@"data"][@"count"] integerValue];
            NSMutableArray *temporaryArray = [NSMutableArray new];
            temporaryArray = [MSAttendanceListModel mj_objectArrayWithKeyValuesArray:responseObject[@"data"][@"attendanceList"]];
            self.attendanceListArray = temporaryArray;
            [self.CollectionView.mj_header endRefreshing];
            [MBManager hideAlert];
        }else{
            [MBManager showBriefAlert:responseObject[@"msg"]];
            [self.CollectionView.mj_header endRefreshing];
            [MBManager hideAlert];
            page = [params[@"page"] integerValue];
        }
        [self.CollectionView reloadData];
    } failure:^(NSError *error) {
        [MBManager hideAlert];
        [MBManager showBriefAlert:Failed];
        [self.CollectionView.mj_header endRefreshing];
    }];
    
}

- (void)FootderRefreshReloadData{
    [MBManager showLoading];
    [self.attendanceListArray removeAllObjects];
    //年龄小
    
    NSMutableDictionary * params = [NSMutableDictionary dictionary];
    
    if (self.ageTextField.text.length == 0) {
        
        params[@"minAge"] = @0;
    }else{
        params[@"minAge"] = self.ageTextField.text;
    }
    
    //年龄大
    if (self.ageTextField.text.length == 0) {
        params[@"maxAge"] = @0;
    }else{
        params[@"maxAge"] = self.ageTextField.text;
    }
    
    //身高小
    if (self.heightTextField.text.length == 0) {
        params[@"minHeight"] = @0;
    }else{
        params[@"minHeight"] = self.heightTextField.text;
    }
    
    //身高大
    if (self.twoheightTextField.text.length == 0) {
        params[@"maxHeight"] = @0;
    }else{
        params[@"maxHeight"] = self.twoheightTextField.text;
    }
    
    //性别
    if (self.SexSelectedButton.tag == 100) {
        params[@"sex"] = @1;
    }else if (self.SexSelectedButton.tag == 101) {
        params[@"sex"] = @0;
    }else{
        params[@"sex"] = @3;
    }
    
    
    //特长
    if (self.selectedButton.tag == 10) {
        params[@"speciality"] = @1;
    }else if (self.SexSelectedButton.tag == 11) {
        params[@"speciality"] = @2;
    }else if (self.SexSelectedButton.tag == 12) {
        params[@"speciality"] = @3;
    }else if (self.SexSelectedButton.tag == 13) {
        params[@"speciality"] = @4;
    }else{
        params[@"speciality"] = @0;
    }
    
    params[@"busId"] = [WYCAccountTool unarchivebelongBusid];
    if (self.nationalityButton.titleLabel.text == nil || self.nationalityButton.titleLabel.text == NULL || [self.nationalityButton.titleLabel.text isKindOfClass:[NSNull class]] || [[self.nationalityButton.titleLabel.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] == 0) {
        params[@"province"] = @"";
    }else if([self.nationalityButton.titleLabel.text isEqualToString:@"请选择"]){
        params[@"province"] = @"";
    }else{
        params[@"province"] = [NSString stringWithFormat:@"%@",self.nationalityButton.titleLabel.text];
    }
    
    if (self.NativeButton.titleLabel.text == nil || self.NativeButton.titleLabel.text == NULL || [self.NativeButton.titleLabel.text isKindOfClass:[NSNull class]] || [[self.NativeButton.titleLabel.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] == 0) {
        params[@"country"] = @"";
    }else if([self.NativeButton.titleLabel.text isEqualToString:@"请选择"]){
        params[@"province"] = @"";
    }else{
        params[@"country"] = [NSString stringWithFormat:@"%@",self.NativeButton.titleLabel.text];
    }
    params[@"page"] = @(page);
    params[@"pageSize"] = @(pageSize);
    
    [HTTPRequest POST:MSattendancePersonnel params:params succeed:^(id responseObject) {
//        WYCLog(@"--------%@",responseObject);
        if (CodeStr) {
            self.attendanceListArray = [MSAttendanceListModel mj_objectArrayWithKeyValuesArray:responseObject[@"data"][@"attendanceList"]];
            [self.CollectionView.mj_footer endRefreshing];
            [MBManager hideAlert];
        }else{
            [MBManager showBriefAlert:responseObject[@"msg"]];
            [self.CollectionView.mj_footer endRefreshing];
            [MBManager hideAlert];
            page --;
        }
        [self.CollectionView reloadData];
    } failure:^(NSError *error) {
        [MBManager hideAlert];
        [MBManager showBriefAlert:Failed];
        [self.CollectionView.mj_footer endRefreshing];
    }];
}
- (void)CreatCollectionHeaderView{
    
    UIView * HeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, [self navBarBottom], ScreenWidth, 200 * px)];
    HeaderView.backgroundColor = backgroundcolor;
    [self.view addSubview:HeaderView];
    
    
    /** 列表*/
    UIButton * listButton = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth * 0.5 + ScreenWidth / 6 , 50 * px, 100 * px, 100 * px)];
    [listButton  setImage:[UIImage imageNamed:@"列表"] forState:UIControlStateNormal];
    [listButton  addTarget:self action:@selector(listButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [HeaderView  addSubview:listButton];
    
    
    UIView * lineView = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(listButton.frame) + 20 * px, listButton.y, 1, listButton.height)];
    lineView.backgroundColor = BackViewColor;
    [HeaderView addSubview:lineView];
    
    
    /** 列表*/
    MSScreenButton * screenButton = [[MSScreenButton alloc] initWithFrame:CGRectMake(CGRectGetMaxX(lineView.frame) + 30 * px, listButton.y, 180 * px, listButton.height)];
    [screenButton setTitle:@"筛选" forState:UIControlStateNormal];
    [screenButton setTitleColor:WYCRGBColor(107, 163, 219) forState:UIControlStateNormal];
    [screenButton setImage:[UIImage imageNamed:@"筛选下拉箭头"] forState:UIControlStateNormal];
    screenButton.titleLabel.font = [UIFont systemFontOfSize:SYRealValue(32 / 2)];
    [screenButton addTarget:self action:@selector(screenButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [HeaderView  addSubview:screenButton];
    self.screenButton = screenButton;
    
}

- (void)screenButtonClick:(UIButton *)sender{
    _isRemove = !_isRemove;
    if (_isRemove == YES)
    {
            [sender setImage:[UIImage imageNamed:@"筛选收起箭头"] forState:UIControlStateNormal];
            [self CreatShowView];
    } else {
        [sender setImage:[UIImage imageNamed:@"筛选下拉箭头"] forState:UIControlStateNormal];
        [self RemoveBack];
    }
}

- (void)CreatShowView{
   
    
    UIView * view = [[UIView alloc] init];
    view.frame = CGRectMake(0, [self navBarBottom] + 200 * px, ScreenWidth, ScreenHeight - [self navBarBottom] - 200 * px);
    view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
    [[UIApplication sharedApplication].keyWindow  addSubview:view];
    self.backView = view;
    
    
    UIView * showView = [[UIView alloc] init];
    showView.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight / 2);
    showView.backgroundColor = backgroundcolor;
    [view addSubview:showView];
    self.showView = showView;
    
    
    /** 年龄*/
    UILabel * ageTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(80 * px, 50 * px, 100 * px, 60 * px)];
    ageTitleLabel.textColor = [UIColor whiteColor];
    ageTitleLabel.text = @"年龄";
    ageTitleLabel.textAlignment = NSTextAlignmentLeft;
    ageTitleLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
    [showView addSubview:ageTitleLabel];
    
    UITextField * ageTextField = [[UITextField alloc] init];
    ageTextField.frame = CGRectMake(CGRectGetMaxX(ageTitleLabel.frame) + 50 * px, ageTitleLabel.y - 10 * px, 300 * px, 80 * px);
    ageTextField.placeholder = @" 0岁";
    ageTextField.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 5, 0)];
    ageTextField.leftViewMode = UITextFieldViewModeAlways;
    ageTextField.backgroundColor = BackViewColor;
    [ageTextField setValue:[UIColor grayColor] forKeyPath:@"_placeholderLabel.textColor"];
    [ageTextField setValue:[UIFont systemFontOfSize:SYRealValue(28 / 2)] forKeyPath:@"_placeholderLabel.font"];
    ageTextField.keyboardType = UIKeyboardTypeNumberPad;
    ageTextField.layer.cornerRadius = 10 * px;
    ageTextField.textColor = [UIColor whiteColor];
    [showView addSubview:ageTextField];
    self.ageTextField = ageTextField;
    
    /** 年龄*/
    UIView * fengeLabel = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(ageTextField.frame) + 30 * px,ageTitleLabel.y + ageTitleLabel.height / 2 - 1, 50 * px, 1)];
    fengeLabel.backgroundColor = [UIColor whiteColor];
    [showView addSubview:fengeLabel];
    
    
    UITextField * twoageTextField = [[UITextField alloc] init];
    twoageTextField.frame = CGRectMake(CGRectGetMaxX(fengeLabel.frame) + 30 * px, ageTextField.y, ageTextField.width,ageTextField.height);
    twoageTextField.placeholder = @" 0岁";
    twoageTextField.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 5, 0)];
    twoageTextField.leftViewMode = UITextFieldViewModeAlways;
    twoageTextField.backgroundColor = BackViewColor;
    [twoageTextField setValue:[UIColor grayColor] forKeyPath:@"_placeholderLabel.textColor"];
    [twoageTextField setValue:[UIFont systemFontOfSize:SYRealValue(28 / 2)] forKeyPath:@"_placeholderLabel.font"];
    twoageTextField.keyboardType = UIKeyboardTypeNumberPad;
    twoageTextField.layer.cornerRadius = 10 * px;
    twoageTextField.textColor = [UIColor whiteColor];
    [showView addSubview:twoageTextField];
    self.twoageTextField= twoageTextField;
    
    
    /** 年龄*/
    UILabel * heightTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(ageTitleLabel.x, CGRectGetMaxY(ageTitleLabel.frame) + 60 * px, ageTitleLabel.width, ageTitleLabel.height)];
    heightTitleLabel.textColor = ageTitleLabel.textColor;
    heightTitleLabel.text = @"身高";
    heightTitleLabel.textAlignment = NSTextAlignmentLeft;
    heightTitleLabel.font = ageTitleLabel.font;
    [showView addSubview:heightTitleLabel];
    
    UITextField * heightTextField = [[UITextField alloc] init];
    heightTextField.frame = CGRectMake(ageTextField.x, heightTitleLabel.y - 10 * px, ageTextField.width, ageTextField.height);
    heightTextField.placeholder = @" CM";
    heightTextField.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 5, 0)];
    heightTextField.leftViewMode = UITextFieldViewModeAlways;
    heightTextField.backgroundColor = BackViewColor;
    [heightTextField setValue:[UIColor grayColor] forKeyPath:@"_placeholderLabel.textColor"];
    [heightTextField setValue:[UIFont systemFontOfSize:SYRealValue(28 / 2)] forKeyPath:@"_placeholderLabel.font"];
    heightTextField.keyboardType = UIKeyboardTypeNumberPad;
    heightTextField.layer.cornerRadius = 10 * px;
    heightTextField.textColor = [UIColor whiteColor];
    [showView addSubview:heightTextField];
    self.heightTextField = heightTextField;
    //
    /** 年龄*/
    UIView * heightLabel = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(heightTextField.frame) + 30 * px,heightTitleLabel.y + heightTitleLabel.height / 2 - 1, fengeLabel.width, fengeLabel.height)];
    heightLabel.backgroundColor = [UIColor whiteColor];
    [showView addSubview:heightLabel];
    
    
    UITextField * twoheightTextField = [[UITextField alloc] init];
    twoheightTextField.frame = CGRectMake(twoageTextField.x, heightTextField.y, heightTextField.width,heightTextField.height);
    twoheightTextField.placeholder = @" CM";
    twoheightTextField.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 5, 0)];
    twoheightTextField.leftViewMode = UITextFieldViewModeAlways;
    twoheightTextField.backgroundColor = BackViewColor;
    [twoheightTextField setValue:[UIColor grayColor] forKeyPath:@"_placeholderLabel.textColor"];
    [twoheightTextField setValue:[UIFont systemFontOfSize:SYRealValue(28 / 2)] forKeyPath:@"_placeholderLabel.font"];
    twoheightTextField.keyboardType = UIKeyboardTypeNumberPad;
    twoheightTextField.layer.cornerRadius = 10 * px;
    twoheightTextField.textColor = [UIColor whiteColor];
    [showView addSubview:twoheightTextField];
    self.twoheightTextField = twoheightTextField;
    
    
    /** 年龄*/
    UILabel * sexTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(ageTitleLabel.x, CGRectGetMaxY(heightTitleLabel.frame) + 60 * px, ageTitleLabel.width, ageTitleLabel.height)];
    sexTitleLabel.textColor = ageTitleLabel.textColor;
    sexTitleLabel.text = @"性别";
    sexTitleLabel.textAlignment = NSTextAlignmentLeft;
    sexTitleLabel.font = ageTitleLabel.font;
    [showView addSubview:sexTitleLabel];
    
    
    UIView * sexView = [[UIView alloc] init];
    sexView.frame = CGRectMake(ageTextField.x, sexTitleLabel.y - 10 * px, 400 * px, 80 * px);
    sexView.backgroundColor = [UIColor clearColor];
    [showView addSubview:sexView];
    
    NSArray * sexTitleArray = @[@"男",@"女"];
    NSArray * sexIMGArray = @[@"筛选-未选中",@"筛选-未选中"];
    NSArray * sexSelectIMGArray = @[@"勾",@"勾"];
    CGFloat width = 130 * px;
    CGFloat height = 60 * px;
    for (NSInteger i = 0; i < sexTitleArray.count; i ++) {
        MSScreenSexButton *Sexbutton = [[MSScreenSexButton alloc] init];
        Sexbutton.tag = i + 100;
        Sexbutton.height = height;
        Sexbutton.width = width;
        Sexbutton.x = (width + 100 * px) * i + 50 * px;
        Sexbutton.y = 10 * px;
        [Sexbutton setTitle:sexTitleArray[i] forState:UIControlStateNormal];
        [Sexbutton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        //                Sexbutton.backgroundColor = [UIColor redColor];
        [Sexbutton setImage:[UIImage imageNamed:sexIMGArray[i]] forState:UIControlStateNormal];
        [Sexbutton setImage:[UIImage imageNamed:sexSelectIMGArray[i]] forState:UIControlStateDisabled];
        [Sexbutton layoutIfNeeded];//强制布局
        Sexbutton.titleLabel.textAlignment = NSTextAlignmentCenter;
        Sexbutton.titleLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
        [Sexbutton addTarget:self action:@selector(titleClick:) forControlEvents:UIControlEventTouchUpInside];
        [sexView addSubview:Sexbutton];
    }
    
    /** 年龄*/
    UILabel * nationalityTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(ageTitleLabel.x, CGRectGetMaxY(sexView.frame) + 60 * px, ageTitleLabel.width, ageTitleLabel.height)];
    nationalityTitleLabel.textColor = ageTitleLabel.textColor;
    nationalityTitleLabel.text = @"国籍";
    nationalityTitleLabel.textAlignment = NSTextAlignmentLeft;
    nationalityTitleLabel.font = ageTitleLabel.font;
    [showView addSubview:nationalityTitleLabel];
    
    
    /** <#name#>*/
    UIButton * nationalityButton = [[UIButton alloc] initWithFrame:CGRectMake(ageTextField.x, nationalityTitleLabel.y - 10 * px, 700 * px, ageTextField.height)];
    [nationalityButton setTitle:@"请选择" forState:UIControlStateNormal];
    nationalityButton.titleLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
    [nationalityButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    nationalityButton.backgroundColor = BackViewColor;
    nationalityButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [nationalityButton  addTarget:self action:@selector(nationalityButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [showView  addSubview:nationalityButton];
    self.nationalityButton = nationalityButton;
    
    /** 箭头*/
    UIButton * jiantouButton = [[UIButton alloc] initWithFrame:CGRectMake(nationalityButton.width - 70 * px, 10 * px, 60 * px, 60 * px)];
    [jiantouButton  setImage:[UIImage imageNamed:@"选择箭头"] forState:UIControlStateNormal];
    [jiantouButton  addTarget:self action:@selector(nationalityButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [nationalityButton  addSubview:jiantouButton];
    
    
    
    /** 年龄*/
    UILabel * NativeTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(ageTitleLabel.x, CGRectGetMaxY(nationalityButton.frame) + 60 * px, ageTitleLabel.width, ageTitleLabel.height)];
    NativeTitleLabel.textColor = ageTitleLabel.textColor;
    NativeTitleLabel.text = @"籍贯";
    NativeTitleLabel.textAlignment = NSTextAlignmentLeft;
    NativeTitleLabel.font = ageTitleLabel.font;
    [showView addSubview:NativeTitleLabel];
    
    
    /** <#name#>*/
    UIButton * NativeButton = [[UIButton alloc] initWithFrame:CGRectMake(nationalityButton.x, NativeTitleLabel.y - 10 * px, nationalityButton.width, nationalityButton.height)];
    [NativeButton setTitle:@"请选择" forState:UIControlStateNormal];
    NativeButton.titleLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
    [NativeButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    NativeButton.backgroundColor = BackViewColor;
    NativeButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [NativeButton  addTarget:self action:@selector(NativeButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [showView  addSubview:NativeButton];
    self.NativeButton = NativeButton;
    
    /** 箭头*/
    UIButton * NativejiantouButton = [[UIButton alloc] initWithFrame:CGRectMake(nationalityButton.width - 70 * px, 10 * px, 60 * px, 60 * px)];
    [NativejiantouButton  setImage:[UIImage imageNamed:@"选择箭头"] forState:UIControlStateNormal];
    [NativejiantouButton  addTarget:self action:@selector(NativeButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [NativeButton  addSubview:NativejiantouButton];
    
    
    /** 年龄*/
    UILabel * SpecialityTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(ageTitleLabel.x, CGRectGetMaxY(NativeButton.frame) + 60 * px, ageTitleLabel.width, ageTitleLabel.height)];
    SpecialityTitleLabel.textColor = ageTitleLabel.textColor;
    SpecialityTitleLabel.text = @"特长";
    SpecialityTitleLabel.textAlignment = NSTextAlignmentLeft;
    SpecialityTitleLabel.font = ageTitleLabel.font;
    [showView addSubview:SpecialityTitleLabel];
    
    
    UIView *SpecialityView = [[UIView alloc] init];
    SpecialityView.frame = CGRectMake(ageTextField.x, SpecialityTitleLabel.y - 10 * px, NativeButton.width, NativeButton.height);
    SpecialityView.backgroundColor = [UIColor clearColor];
    [showView addSubview:SpecialityView];
    
    
    NSArray * SpeTitleArray = @[@"歌曲",@"舞蹈",@"外语",@"其他"];
    CGFloat titleButtonW = (SpecialityView.width - 120 * px) / SpeTitleArray.count;
    CGFloat titleButtonY = 0;
    CGFloat titleButtonH = SpecialityView.height;
    for (NSInteger j = 0; j < SpeTitleArray.count; j ++) {
        UIButton *Spebutton = [[UIButton alloc] init];
        Spebutton.tag = j + 10;
        Spebutton.height = titleButtonH;
        Spebutton.width = titleButtonW;
        Spebutton.x = (width + 55 * px) * j;
        Spebutton.y = titleButtonY;
        [Spebutton setTitle:SpeTitleArray[j] forState:UIControlStateNormal];
        Spebutton.layer.borderColor = [UIColor darkGrayColor].CGColor;//设置边框颜色
        Spebutton.layer.borderWidth = 1.0f;//设置边框颜色
        [Spebutton setBackgroundImage:[UIImage imageWithColor:[UIColor clearColor]] forState:UIControlStateNormal];
        [Spebutton setBackgroundImage:[UIImage imageWithColor:FontColor] forState:UIControlStateDisabled];
        Spebutton.titleLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
        [Spebutton  setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [Spebutton layoutIfNeeded];//强制布局
        Spebutton.titleLabel.textAlignment = NSTextAlignmentCenter;
        [Spebutton addTarget:self action:@selector(SpebuttonClick:) forControlEvents:UIControlEventTouchUpInside];
        [SpecialityView addSubview:Spebutton];
    }
    
    /** 重置*/
    UIButton * chongzhiButton = [[UIButton alloc] initWithFrame:CGRectMake(0, showView.height - 120 * px, showView.width / 2, 120 * px)];
    [chongzhiButton setTitle:@"重置" forState:UIControlStateNormal];
    chongzhiButton.titleLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
    chongzhiButton.backgroundColor = BackViewColor;
    [chongzhiButton  setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [chongzhiButton  addTarget:self action:@selector(chongzhiButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [showView  addSubview:chongzhiButton];
    
    
    /** 重置*/
    UIButton * quedingButton = [[UIButton alloc] initWithFrame:CGRectMake(showView.width / 2, chongzhiButton.y, chongzhiButton.width, chongzhiButton.height)];
    [quedingButton setTitle:@"确定" forState:UIControlStateNormal];
    [quedingButton setBackgroundImage:[UIImage imageNamed:@"底部按钮背景"] forState:UIControlStateNormal];
    quedingButton.titleLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
    [quedingButton  setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [quedingButton  addTarget:self action:@selector(quedingButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [showView addSubview:quedingButton];
}
- (void)chongzhiButtonClick{
    
    
    
    self.ageTextField.text = @"";
    self.twoageTextField.text = @"";
    self.heightTextField.text = @"";
    self.twoheightTextField.text = @"";
    
    self.SexSelectedButton.tag = 3;
    self.selectedButton.tag = 0;
    
    [self RemoveBack];
    
    [self CreatShowView];
    
}

- (void)quedingButtonClick{
    
//    WYCLog(@"------%ld",(long)self.SexSelectedButton.tag);
    
    [self ReloadData];
    
    [self RemoveBack];
}
- (UIImage *)imageWithColor:(UIColor *)color
{
    CGRect rect=CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context=UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    
    UIImage *image=UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}
- (void)SpebuttonClick:(UIButton *)sender{
    self.selectedButton.enabled = YES;
    sender.enabled = NO;
    self.selectedButton = sender;
    
}
//国籍选择
- (void)nationalityButtonClick{
    
    NSString *filePath = [[NSBundle mainBundle]pathForResource:@"nationality-zh" ofType:@"json"];
    NSData *data = [[NSData alloc] initWithContentsOfFile:filePath];
    
   NSArray * arr = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
    
//    NSLog(@"%@",arr);
    NSMutableArray * listName = [NSMutableArray new];
    for (NSDictionary * dict in arr) {
        [listName addObject:dict[@"name"]];
        
    }
    zySheetPickerView *pickerView = [zySheetPickerView ZYSheetStringPickerWithTitle:listName andHeadTitle:@"" Andcall:^(zySheetPickerView *pickerView, NSString *choiceString) {
        [self.nationalityButton setTitle:choiceString forState:UIControlStateNormal];
        [pickerView dismissPicker];
    }];
    [pickerView show];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectText:(NSString *)text {
    
    [self.nationalityButton setTitle:text forState:UIControlStateNormal];
}
- (void)NativeButtonClick{
        
    [FYLCityPickView showPickViewWithComplete:^(NSArray *arr) {
        
        NSString *str =  [self replaceUnicode:[NSString stringWithFormat:@"%@%@",arr[0],arr[1]]];
        [self.NativeButton setTitle:str forState:UIControlStateNormal];
        
    } withProvince:@"北京" withCity:@"北京市" withTown:nil withThreeScroll:YES];
    
}
/**
 转码为中文
 
 @param TransformUnicodeString 转码前
 @return 转码后
 */
-(NSString*) replaceUnicode:(NSString*)TransformUnicodeString

{
    
    NSString*tepStr1 = [TransformUnicodeString stringByReplacingOccurrencesOfString:@"\\u"withString:@"\\U"];
    NSString*tepStr2 = [tepStr1 stringByReplacingOccurrencesOfString:@"\""withString:@"\\\""];
    NSString*tepStr3 = [[@"\""  stringByAppendingString:tepStr2]stringByAppendingString:@"\""];
    NSData*tepData = [tepStr3  dataUsingEncoding:NSUTF8StringEncoding];
    NSString*axiba = [NSPropertyListSerialization propertyListWithData:tepData options:NSPropertyListMutableContainers format:NULL error:NULL];
    
    return  [axiba stringByReplacingOccurrencesOfString:@"\\r\\n"withString:@"\n"];
    
}
- (void)titleClick:(UIButton *)sender{
    //修改按钮状态
    self.SexSelectedButton.enabled = YES;
    sender.enabled = NO;
    self.SexSelectedButton = sender;
}
- (void)RemoveBack{
    
     [self.screenButton setImage:[UIImage imageNamed:@"筛选下拉箭头"] forState:UIControlStateNormal];
    [self.backView removeFromSuperview];
    
    
    
}
- (void)listButtonClick:(UIButton *)sender{
    _isGrid = !_isGrid;
//    [self.CollectionView reloadData];
    
    if (_isGrid == YES)
    {
        [self ReloadData];
        [sender setImage:[UIImage imageNamed:@"列表"] forState:UIControlStateNormal];
    } else {
        [self ReloadData];
        [sender setImage:[UIImage imageNamed:@"卡片"] forState:UIControlStateNormal];
    }
    
}
- (void)CreatCollectionView{
    
    //1.初始化layout
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    //设置collectionView滚动方向
    //
    [layout setScrollDirection:UICollectionViewScrollDirectionVertical];
    //设置headerView的尺寸大小
    layout.headerReferenceSize = CGSizeMake(ScreenWidth, self.CollectionHeaderView.height);
    //该方法也可以设置itemSize
    //    layout.itemSize = CGSizeMake(744 * px, 438 * px);
    //2.初始化collectionView
    
    
    
    
    self.CollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, [self navBarBottom] + 200 * px, ScreenWidth, ScreenHeight - [self navBarBottom] - 200 * px) collectionViewLayout:layout];
    //注册cell
    [self.CollectionView registerClass:[MSSeeStatisticsCell class] forCellWithReuseIdentifier:@"cellId"];
//    self.CollectionView.showsVerticalScrollIndicator = NO;
    //4.设置代理
    self.CollectionView.delegate = self;
    
    self.CollectionView.dataSource = self;
    self.CollectionView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:self.CollectionView];
}

#pragma mark collectionView代理方法
//返回section个
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;

}
//设置每个分区的item个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.attendanceListArray.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
//    [self.CollectionView reloadData];
    MSSeeStatisticsCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellId forIndexPath:indexPath];
    cell.contentView.backgroundColor = backgroundcolor;
    if (!cell)
    {
        cell = [[MSSeeStatisticsCell alloc] initWithFrame:CGRectMake(0, [self navBarBottom] + 200 * px, ScreenWidth, ScreenHeight - [self navBarBottom] - 200 * px)];
    }
    cell.isGrid = _isGrid;
    cell.AttendanceListModel = self.attendanceListArray[indexPath.row];
    return cell;
    
}
//设置每个item的尺寸
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    if (_isGrid == YES) {
        return CGSizeMake(ScreenWidth / 2 - 10 * px, 700 * px);
    }else{
        
        return CGSizeMake(ScreenWidth, 300 * px);
    }
    
    
}

//设置每个item水平间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
    if (_isGrid == YES) {
        return 10 * px;
        
    }else{
        return 0;
    }
    
}
//设置每个item垂直间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
    if (_isGrid == YES) {
        return 20 * px;
        
    }else{
        return 0;
    }
    
}


#pragma mark -UICollectionViewDelegate
//UICollectionView被选中的时候调用
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"%zd",indexPath.item);
    MSAttendanceListModel * Model = self.attendanceListArray[indexPath.row];
    MSShowPersonController * showVC = [[MSShowPersonController alloc] init];
    showVC.TagStr = Model.uid;
    [self.navigationController pushViewController:showVC animated:NO];
    
}
// 返回这个UICollectionView是否可以被选择
- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
    
}
- (void)CreateNavigationBar{
    
    self.view.backgroundColor = backgroundcolor;
    naviagtionBar = [[CustomNavigationBar alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, [self navBarBottom])];
    [self.view addSubview:naviagtionBar];
    naviagtionBar.titleLabel.text = @"出勤人员列表";
    naviagtionBar.rightBtn.hidden = YES;
    naviagtionBar.rightBtnTitle.hidden = YES;
//    naviagtionBar.leftBtn.hidden = YES;
    [self.view addSubview:naviagtionBar];
    
    [naviagtionBar.leftBtn setImage:[UIImage imageNamed:@"左箭头"] forState:UIControlStateNormal];
    [naviagtionBar.leftBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
    
}

- (void)backClick{
    [self RemoveBack];
    [self.navigationController popViewControllerAnimated:NO];
}

@end
